package com.santu.edu.supporter.biz.user.dao;

import cn.hutool.core.collection.CollUtil;
import com.santu.edu.supporter.biz.user.dao.mapper.UserAddressMapper;
import com.santu.edu.supporter.biz.user.pojo.dto.UserAddressDTO;
import com.santu.edu.supporter.biz.user.pojo.po.UserAddressPO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @author luoyaoqi
 * @createTime 2024/2/20
 * @description
 */
@Repository
@RequiredArgsConstructor
public class UserAdressDao {

    private final UserAddressMapper addressMapper;

    public void addUserAddress(UserAddressDTO dto) {
        UserAddressPO item = UserAddressPO.createItem(dto);
        addressMapper.insertOne(item);
    }

    public void updateUserAddress(UserAddressDTO dto) {
        UserAddressPO item = UserAddressPO.createItem(dto);
        addressMapper.updateOne(item);
    }

    public void removeUserAddress(String addressId) {
        addressMapper.removeOne(addressId);
    }

    public List<UserAddressDTO> getUserAddressList(String userId) {
        List<UserAddressDTO> userAddressList = addressMapper.getUserAddressList(userId);
        if (CollUtil.isEmpty(userAddressList)) {
            return Collections.emptyList();
        }
        return userAddressList;
    }
}
